//
//  LSContactsViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/28.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSContactsViewController.h"
#import "NZKScrollView.h"
#import "NZKCollectionView.h"
#import "ContactModel.h"
#import "ContactDataHelper.h"//根据拼音A~Z~#进行排序的tool
#import "LSContactsWithinTableViewCell.h"

#import "LSYellowPageCollectionViewCell.h"
#import "FEWebViewController.h"
#import "LSContactListViewController.h"
#import "LSContactsDetailViewController.h"

#define BottomLineMargin 0
#define headerSelectViewHeight 50
#define CountPerPage 1000

@interface LSContactsViewController () <UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, UITextFieldDelegate>
{
    NSArray *_rowArr;//row arr
    NSArray *_sectionArr;//section arr
}
@property (nonatomic, strong) NSArray *displayRowArr;
@property (nonatomic, strong) NSArray *displaySectionArr;
@property (nonatomic, strong) NZKScrollView *mainScrollView;
@property (nonatomic, strong) UIScrollView *bottomLineScrollView;
@property (nonatomic, strong) NSArray *headerSelectContentArray;
@property (nonatomic, strong) NSMutableArray *headerSelectButtonsArray;
@property (nonatomic, strong) UIView *allTableViewSearchView;
@property (nonatomic, strong) UITableView *allTableView;
@property (nonatomic, assign) int tableViewPage;
@property (nonatomic, strong) NSMutableArray *dataArrayM;
@property (nonatomic, strong) UITableView *departmentTableView;
@property (nonatomic, strong) NZKCollectionView *collectionView;

@property (nonatomic, strong) NSArray *dataArr;
@property (nonatomic, strong) NSMutableArray *dataArrM;

@property (nonatomic, strong) NSArray *yellowPageContentArray;
@end

static NSString *LSYellowPageCollectionViewCellID = @"LSYellowPageCollectionViewCellID";
static NSString *LSContactsWithinTableViewCellID = @"LSContactsWithinTableViewCellID";

@implementation LSContactsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"通讯录";
    [self.view addSubview:self.mainScrollView];
    [self loadData];
    [self.mainScrollView addSubview:self.allTableView];
    _allTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    self.allTableView.sectionIndexColor = NAV_COLOR;
    self.allTableView.sectionIndexBackgroundColor = [UIColor clearColor];
//    for (NSDictionary *subDic in self.dataArr) {
//        ContactModel *model = [[ContactModel alloc] initWithDic:subDic];
//        [self.dataArrM addObject:model];
//    }
//    _rowArr = [ContactDataHelper getFriendListDataBy:self.dataArrM];
//    _sectionArr = [ContactDataHelper getFriendListSectionBy:[_rowArr mutableCopy]];
    _rowArr = @[];
    _sectionArr = @[];
    [self.mainScrollView addSubview:self.collectionView];
    [self setUpHeaderSelectView];
}

- (void)setUpHeaderSelectView {
    UIView *headerSelectView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, headerSelectViewHeight)];
    headerSelectView.backgroundColor = UIColor.whiteColor;
    for (int i = 0; i < self.headerSelectContentArray.count; i++) {
        UIButton *headerSelectButton = [[UIButton alloc] initWithFrame:CGRectMake((ScreenWidth/self.headerSelectContentArray.count)*i, 0, ScreenWidth/self.headerSelectContentArray.count, headerSelectViewHeight)];
        if (i == 0) {
            headerSelectButton.selected = true;
        }
        [headerSelectButton setTitle:self.headerSelectContentArray[i] forState:UIControlStateNormal];
        [headerSelectButton setTitleColor:NAV_COLOR forState:UIControlStateSelected];
        [headerSelectButton setTitleColor:hexColor(666666) forState:UIControlStateNormal];
        headerSelectButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15];
        headerSelectButton.tag = i+TagFoundation;
        [headerSelectButton addTarget:self action:@selector(headerSelectButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [headerSelectView addSubview:headerSelectButton];
        [self.headerSelectButtonsArray addObject:headerSelectButton];
    }
    UIView *bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, headerSelectViewHeight-0.5, ScreenWidth, 0.5)];
    bottomLineView.backgroundColor = hexColor(EEEEEE);
    [headerSelectView addSubview:bottomLineView];
    UIScrollView *bottomLineScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, headerSelectViewHeight-1, ScreenWidth, 1)];
    self.bottomLineScrollView = bottomLineScrollView;
    bottomLineScrollView.backgroundColor = UIColor.clearColor;
    bottomLineScrollView.contentSize = CGSizeMake((ScreenWidth/self.headerSelectContentArray.count*(self.headerSelectContentArray.count*2-1)), 1);
    UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake((ScreenWidth/self.headerSelectContentArray.count*(self.headerSelectContentArray.count-1))+BottomLineMargin, 0, ScreenWidth/self.headerSelectContentArray.count-BottomLineMargin*2, 1)];
    bottomLine.backgroundColor = NAV_COLOR;
    [bottomLineScrollView addSubview:bottomLine];
    [bottomLineScrollView setContentOffset:CGPointMake(ScreenWidth/self.headerSelectContentArray.count*(self.headerSelectContentArray.count-1), 0)];
    [headerSelectView addSubview:bottomLineScrollView];
    [self.view addSubview:headerSelectView];
}

- (void)headerSelectButtonClick:(UIButton *)button {
    NSInteger page = button.tag-TagFoundation;
    for (int i = 0; i < self.headerSelectButtonsArray.count; i++) {
        UIButton *button = self.headerSelectButtonsArray[i];
        if (i == page) {
            button.selected = true;
        } else {
            button.selected = false;
        }
    }
    [self.bottomLineScrollView setContentOffset:CGPointMake((ScreenWidth/self.headerSelectButtonsArray.count*(self.headerSelectButtonsArray.count-1))-ScreenWidth/self.headerSelectContentArray.count*page, 0) animated:true];
    [self.mainScrollView setContentOffset:CGPointMake(ScreenWidth*page, 0) animated:true];
}

- (void)loadData {
    self.tableViewPage = 1;
    NSDictionary *param = @{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"rows":[NSString stringWithFormat:@"%d",CountPerPage],@"page":[NSString stringWithFormat:@"%d",self.tableViewPage]};
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:ContactBook param:param completionHandler:^(id responseObject, NSError *connectionError) {
        [hud hideAnimated:true];
        self.allTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
        [self.allTableView.mj_header endRefreshing];
        if (!connectionError) {
            NSArray *dataArray = [responseObject objectForKey:@"data"];
            if (dataArray && dataArray.count > 0) {
                self.dataArrayM = [[NSMutableArray alloc] initWithArray:dataArray];
                if (self.dataArrayM.count < self.tableViewPage*CountPerPage) {
                    [self.allTableView.mj_footer endRefreshingWithNoMoreData];
                }
                [self.dataArrM removeAllObjects];
                for (NSDictionary *subDic in dataArray) {
                    ContactModel *model = [[ContactModel alloc] initWithDic:subDic];
                    [self.dataArrM addObject:model];
                }
                _rowArr = [ContactDataHelper getFriendListDataBy:self.dataArrM];
                _sectionArr = [ContactDataHelper getFriendListSectionBy:[_rowArr mutableCopy]];
                self.displayRowArr = _rowArr;
                self.displaySectionArr = _sectionArr;
                [self.allTableView reloadData];
            } else {
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}

- (void)loadMoreData {
    self.tableViewPage++;
    NSDictionary *param = @{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"rows":[NSString stringWithFormat:@"%d",CountPerPage],@"page":[NSString stringWithFormat:@"%d",self.tableViewPage]};
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:ContactBook param:param completionHandler:^(id responseObject, NSError *connectionError) {
        if (!connectionError) {
            NSArray *dataArray = [responseObject objectForKey:@"data"];
            if (dataArray && dataArray.count > 0) {
                [self.dataArrayM addObjectsFromArray:dataArray];
                if (self.dataArrayM.count < self.tableViewPage*CountPerPage) {
                    [self.allTableView.mj_footer endRefreshingWithNoMoreData];
                } else {
                    [self.allTableView.mj_footer endRefreshing];
                }
                [self.allTableView reloadData];
            } else {
                self.tableViewPage--;
                [self.allTableView.mj_footer endRefreshingWithNoMoreData];
            }
        } else {
            self.tableViewPage--;
            [self.allTableView.mj_footer endRefreshing];
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString * str = [textField.text stringByReplacingCharactersInRange:range withString:string];
    if ([str isEqualToString:@""]) {
        self.displayRowArr = _rowArr;
        self.displaySectionArr = _sectionArr;
    } else {
        NSMutableArray *rowArrM = [[NSMutableArray alloc] initWithArray:_rowArr];
        NSMutableArray *sectionArrM = [[NSMutableArray alloc] initWithArray:_sectionArr];
        for (int i = 0; i < rowArrM.count; i++) {
            NSArray *section = rowArrM[i];
            NSMutableArray *sectionM = [[NSMutableArray alloc] initWithArray:section];
            for (int j = 0; j < section.count; j++) {
                ContactModel *model = section[j];
                if ([model.name rangeOfString:str].length <= 0 && [model.mobile rangeOfString:str].length <= 0) {
                    [sectionM removeObject:model];
                }
            }
            [rowArrM replaceObjectAtIndex:i withObject:sectionM.copy];
        }
        NSMutableArray *rowArrrM = [[NSMutableArray alloc] initWithArray:@[]];
        NSMutableArray *sectionArrrM = [[NSMutableArray alloc] initWithArray:@[]];
        for (int i = 0; i < rowArrM.count; i++) {
            NSArray *section = rowArrM[i];
            if (section.count <= 0) {
                [rowArrrM addObject:rowArrM[i]];
                [sectionArrrM addObject:sectionArrM[i]];
            }
        }
        [rowArrM removeObjectsInArray:rowArrrM];
        [sectionArrM removeObjectsInArray:sectionArrrM];
        self.displayRowArr = rowArrM.copy;
        self.displaySectionArr = sectionArrM.copy;
    }
    [self.allTableView reloadData];
    return true;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    //section
    return self.displayRowArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //row
    return [self.displayRowArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LSContactsWithinTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSContactsWithinTableViewCellID forIndexPath:indexPath];
    ContactModel *model=self.displayRowArr[indexPath.section][indexPath.row];
    cell.model = model;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    if (tableView == self.allTableView) {
        ContactModel *model=self.displayRowArr[indexPath.section][indexPath.row];
        LSContactsDetailViewController *contactsDetailVC = [[LSContactsDetailViewController alloc] init];
        contactsDetailVC.model = model;
        [self.navigationController pushViewController:contactsDetailVC animated:true];
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    // viewforHeader
    id label = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
    if (!label) {
        label = [[UILabel alloc] init];
        [label setFont:[UIFont fontWithName:@"PingFang-SC-Medium" size:12]];
        [label setTextColor:hexColor(333333)];
        [label setBackgroundColor:hexColor(EEEEEE)];
    }
    [label setText:[NSString stringWithFormat:@"    %@",self.displaySectionArr[section]]];
    return label;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return self.displaySectionArr;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    return index;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 22.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return LSContactsWithinTableViewCellHeight;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.mainScrollView) {
        CGFloat mainScrollViewContentOffsetX = scrollView.contentOffset.x;
        [self.bottomLineScrollView setContentOffset:CGPointMake((ScreenWidth/self.headerSelectButtonsArray.count*(self.headerSelectButtonsArray.count-1))-mainScrollViewContentOffsetX/self.headerSelectButtonsArray.count, 0)];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat mainScrollViewContentOffsetX = scrollView.contentOffset.x;
    NSInteger page = mainScrollViewContentOffsetX/ScreenWidth;
    for (int i = 0; i < self.headerSelectButtonsArray.count; i++) {
        UIButton *button = self.headerSelectButtonsArray[i];
        if (i == page) {
            button.selected = true;
        } else {
            button.selected = false;
        }
    }
}

- (NZKScrollView *)mainScrollView {
    if (!_mainScrollView) {
        _mainScrollView = [[NZKScrollView alloc] initWithFrame:CGRectMake(0, headerSelectViewHeight, ScreenWidth, ScreenHeight-SafeAreaTopHeight-headerSelectViewHeight)];
        _mainScrollView.backgroundColor = hexColor(EEEEEE);
        _mainScrollView.delegate = self;
        _mainScrollView.contentSize = CGSizeMake(ScreenWidth*2, ScreenHeight-SafeAreaTopHeight-headerSelectViewHeight);
        _mainScrollView.showsVerticalScrollIndicator = false;
        _mainScrollView.showsHorizontalScrollIndicator = false;
        _mainScrollView.pagingEnabled = true;
    }
    return _mainScrollView;
}

#pragma mark - allTableView相关
- (UITableView *)allTableView {
    if (!_allTableView) {
        _allTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight-headerSelectViewHeight)];
        _allTableView.backgroundColor = hexColor(ffffff);
        _allTableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 0);
        _allTableView.dataSource = self;
        _allTableView.delegate = self;
        _allTableView.tableFooterView = [UIView new];
        _allTableView.tableHeaderView = self.allTableViewSearchView;
        [_allTableView registerClass:LSContactsWithinTableViewCell.class forCellReuseIdentifier:LSContactsWithinTableViewCellID];
    }
    return _allTableView;
}

- (UIView *)allTableViewSearchView {
    if (!_allTableViewSearchView) {
        _allTableViewSearchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
        UITextField *searchInfoTF = [[UITextField alloc] initWithFrame:CGRectMake(12, 4, ScreenWidth-24, 35)];
        searchInfoTF.delegate = self;
        searchInfoTF.placeholder = @"请输入关键字";
        searchInfoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
        searchInfoTF.returnKeyType = UIReturnKeySearch;
        searchInfoTF.layer.cornerRadius = 4;
        searchInfoTF.layer.masksToBounds = true;
        searchInfoTF.layer.borderColor = hexColor(CCCCCC).CGColor;
        searchInfoTF.layer.borderWidth = 1;
        [_allTableViewSearchView addSubview:searchInfoTF];
        searchInfoTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 1)];
        searchInfoTF.leftViewMode = UITextFieldViewModeAlways;
    }
    return _allTableViewSearchView;
}

- (NSArray *)headerSelectContentArray {
    if (!_headerSelectContentArray) {
        _headerSelectContentArray = @[@"全部",@"黄页"];
    }
    return _headerSelectContentArray;
}

- (NSMutableArray *)headerSelectButtonsArray {
    if (!_headerSelectButtonsArray) {
        _headerSelectButtonsArray = [[NSMutableArray alloc] init];
    }
    return _headerSelectButtonsArray;
}

- (NSArray *)dataArr {
    if (!_dataArr) {
        _dataArr = @[@{@"name":@"阿Sa",@"phone":@"3456787765"},
                     @{@"name":@"巴蒂",@"phone":@"56787654765"},
                     @{@"name":@"吃哒",@"phone":@"654898765"},
                     @{@"name":@"弟弟",@"phone":@"23456767"},
                     @{@"name":@"恩爱",@"phone":@"345678987654"},
                     @{@"name":@"风云",@"phone":@"09878909"},
                     @{@"name":@"贵的",@"phone":@"1234543212"},
                     @{@"name":@"黄中国",@"phone":@"4567656778"},
                     @{@"name":@"经典",@"phone":@"9870987687"},
                     @{@"name":@"控控",@"phone":@"876587654321"},
                     @{@"name":@"凉凉",@"phone":@"23456543456789"},
                     @{@"name":@"明明",@"phone":@"2345654345678"},
                     @{@"name":@"您好",@"phone":@"9878987654"},
                     @{@"name":@"哦哦哦",@"phone":@"765678743"},
                     @{@"name":@"啪啪啪",@"phone":@"45676434"},
                     @{@"name":@"清除",@"phone":@"9876898"},
                     @{@"name":@"人人",@"phone":@"4565434578"},
                     @{@"name":@"宋保工",@"phone":@"98789873"},
                     @{@"name":@"婷婷",@"phone":@"9876765"},
                     @{@"name":@"王巴丹",@"phone":@"76545654321"}];
    }
    return _dataArr;
}

- (NSMutableArray *)dataArrM {
    if (!_dataArrM) {
        _dataArrM = [[NSMutableArray alloc] init];
    }
    return _dataArrM;
}

#pragma mark - 部门相关
- (UITableView *)departmentTableView {
    if (!_departmentTableView) {
        _departmentTableView = [[UITableView alloc] initWithFrame:CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight-headerSelectViewHeight)];
        _departmentTableView.backgroundColor = hexColor(ffffff);
        _departmentTableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 0);
        _departmentTableView.dataSource = self;
        _departmentTableView.delegate = self;
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SafeAreaBottomHeight)];
        footerView.backgroundColor = hexColor(ffffff);
        _departmentTableView.tableFooterView = footerView;
        _departmentTableView.tableHeaderView = self.allTableViewSearchView;
        if (@available(iOS 11.0, *)) {
            _departmentTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
            // Fallback on earlier versions
        }
    }
    return _departmentTableView;
}

#pragma mark - 黄页相关
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.yellowPageContentArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LSYellowPageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:LSYellowPageCollectionViewCellID forIndexPath:indexPath];
    cell.content = self.yellowPageContentArray[indexPath.item];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView deselectItemAtIndexPath:indexPath animated:true];
    if (indexPath.item == 1) {
        FEWebViewController *kuaidi = [[FEWebViewController alloc] init];
        kuaidi.title = @"快递";
        kuaidi.UrlString = @"https://m.kuaidi100.com/all/";
        [self.navigationController pushViewController:kuaidi animated:true];
        return;
    }
    LSContactListViewController *contactListVC = [[LSContactListViewController alloc] init];
    contactListVC.title = self.yellowPageContentArray[indexPath.item];
    switch (indexPath.item) {
        case 0:
            contactListVC.displayListArray = @[@{@"name":@"农业银行",@"phone":@"95599"},
                                               @{@"name":@"建设银行",@"phone":@"95533"},
                                               @{@"name":@"中国银行",@"phone":@"95566"},
                                               @{@"name":@"工商银行",@"phone":@"95588"},
                                               @{@"name":@"交通银行",@"phone":@"95559"},
                                               @{@"name":@"招商银行",@"phone":@"95555"},
                                               @{@"name":@"华夏银行",@"phone":@"95577"},
                                               @{@"name":@"兴业银行",@"phone":@"95561"},
                                               @{@"name":@"深圳发展银行",@"phone":@"95501"},
                                               @{@"name":@"中信银行",@"phone":@"95558"},
                                               @{@"name":@"民生银行",@"phone":@"95568"},
                                               @{@"name":@"上海浦东发展银行",@"phone":@"95528"},
                                               @{@"name":@"光大银行",@"phone":@"95595"},
                                               @{@"name":@"微商银行",@"phone":@"96588"},
                                               @{@"name":@"邮政储蓄银行",@"phone":@"95580"}];
            break;
        case 2:
            contactListVC.displayListArray = @[@{@"name":@"中国平安保险",@"phone":@"95511"},
                                               @{@"name":@"中国人寿保险",@"phone":@"95519"},
                                               @{@"name":@"中国太平洋保险",@"phone":@"95500"},
                                               @{@"name":@"中国太平洋人寿保险",@"phone":@"95589"},
                                               @{@"name":@"中国人保保险",@"phone":@"95518"},
                                               @{@"name":@"天安保险",@"phone":@"95505"},
                                               @{@"name":@"大众保险",@"phone":@"95507"},
                                               @{@"name":@"华泰财险",@"phone":@"95509"},
                                               @{@"name":@"中华联合保险",@"phone":@"95585"},
                                               @{@"name":@"华安财险",@"phone":@"95556"},
                                               @{@"name":@"中国大地保险",@"phone":@"95590"},
                                               @{@"name":@"安邦财险",@"phone":@"95569"},
                                               @{@"name":@"泰康人寿保险",@"phone":@"95522"},
                                               @{@"name":@"新华人寿保险",@"phone":@"96567"},
                                               @{@"name":@"信诚人寿保险",@"phone":@"65588598"}];
            break;
        case 3:
            contactListVC.displayListArray = @[@{@"name":@"淘宝网",@"phone":@"0571-88158198"},
                                               @{@"name":@"京东商城",@"phone":@"400-606-5500"},
                                               @{@"name":@"苏宁易购",@"phone":@"400-676-6766"},
                                               @{@"name":@"1号店",@"phone":@"400-007-1111"},
                                               @{@"name":@"天猫",@"phone":@"400-860-8608"},
                                               @{@"name":@"亚马逊",@"phone":@"400-810-5666"},
                                               @{@"name":@"国美在线",@"phone":@"400-819-9777"}];
            break;
        case 4:
            contactListVC.displayListArray = @[@{@"name":@"拉萨市政府热线",@"phone":@"12345"},
                                               @{@"name":@"中国移动通讯",@"phone":@"10086"},
                                               @{@"name":@"中国联通",@"phone":@"10010"},
                                               @{@"name":@"中国电信",@"phone":@"10001"},
                                               @{@"name":@"安居客",@"phone":@"400-615-1357"},
                                               @{@"name":@"农夫山泉",@"phone":@"400-809-6666"},
                                               @{@"name":@"新浪",@"phone":@"400-690-0000"},
                                               @{@"name":@"新华社",@"phone":@"010-63071114"},
                                               @{@"name":@"中央电视台",@"phone":@"010-88047123"}];
            break;
        case 5:
            contactListVC.displayListArray = @[@{@"name":@"火警电话",@"phone":@"119"},
                                               @{@"name":@"水上遇险求救电话",@"phone":@"12395"},
                                               @{@"name":@"报警服务台",@"phone":@"110"},
                                               @{@"name":@"气象服务电话",@"phone":@"12121"},
                                               @{@"name":@"急救电话",@"phone":@"120"},
                                               @{@"name":@"报时服务电话",@"phone":@"12117"},
                                               @{@"name":@"道路交通事故报警台",@"phone":@"122"},
                                               @{@"name":@"红十字会急救台",@"phone":@"999"},
                                               @{@"name":@"公安短信报警号码",@"phone":@"12110"},
                                               @{@"name":@"森林火警电话",@"phone":@"95119"},
                                               @{@"name":@"查号台",@"phone":@"114"},
                                               @{@"name":@"紧急呼叫中心",@"phone":@"112"},
                                               @{@"name":@"邮政客户服务电话",@"phone":@"11185"},
                                               @{@"name":@"全国铁路客服中心",@"phone":@"12306"},
                                               @{@"name":@"全国法律服务热线",@"phone":@"12348"}];
            break;
        case 6:
            contactListVC.displayListArray = @[@{@"name":@"携程网",@"phone":@"400-820-6666"},
                                               @{@"name":@"艺龙网",@"phone":@"400-933-3333"},
                                               @{@"name":@"同程网",@"phone":@"400-777-7777"},
                                               @{@"name":@"芒果网",@"phone":@"400-664-0066"},
                                               @{@"name":@"途牛网",@"phone":@"400-799-9999"},
                                               @{@"name":@"去哪儿网",@"phone":@"10101234"}];
            break;
        case 7:
            contactListVC.displayListArray = @[@{@"name":@"支付宝",@"phone":@"95188"},
                                               @{@"name":@"微信支付",@"phone":@"95017"},
                                               @{@"name":@"银联支付",@"phone":@"95516"}];
            break;
            
        default:
            break;
    }
    [self.navigationController pushViewController:contactListVC animated:true];
}

- (NZKCollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(ScreenWidth/3, 120);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        // 设置左右缩进
        flowLayout.sectionInset = UIEdgeInsetsZero;
        _collectionView = [[NZKCollectionView alloc] initWithFrame:CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight-headerSelectViewHeight) collectionViewLayout:flowLayout];
        // 1.设置分页效果
        _collectionView.pagingEnabled = NO;
        // 2.开启弹簧效果
        _collectionView.bounces = YES;
        // 3.关闭底部的滚动条
        _collectionView.showsHorizontalScrollIndicator = NO;
        // 4.开启滑动
        _collectionView.scrollEnabled = true;
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[LSYellowPageCollectionViewCell class] forCellWithReuseIdentifier:LSYellowPageCollectionViewCellID];
    }
    return _collectionView;
}

- (NSArray *)yellowPageContentArray {
    if (!_yellowPageContentArray) {
        _yellowPageContentArray = @[@"银行",@"快递",@"保险",@"电商",@"生活服务",@"通讯",@"商旅",@"支付工具"];
    }
    return _yellowPageContentArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
